package com.heima.item.listener;

import com.alibaba.fastjson.JSON;
import com.heima.constant.MQConstant;
import com.heima.dto.DeductStockDTO;
import com.heima.item.service.IItemService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class OrderListener {

    @Autowired
    IItemService itemService;

    @RabbitListener(queues = MQConstant.DEDUCT_STOCK_QUEUE)
    public void createOrderMsg(String msg){
        List<DeductStockDTO> dtos = JSON.parseArray(msg, DeductStockDTO.class);
        itemService.deductStock(dtos);
    }
}
